// pages/card/secondBatch/shipin/shipin.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list:[]
    },
    onLoad: function() {
        this.setData({
            'list': app.globalData.baogao
        });
    },
    open(e){
      console.log(e.currentTarget.dataset.url);
        app.showLoading("正在打开...");
        let self = this;
        wx.downloadFile({
            url: e.currentTarget.dataset.url,
            success: function (res) {
              var filePath = res.tempFilePath
              let that = self;
               wx.openDocument({
                 filePath: filePath,
                 success: function (res) {
                    wx.hideLoading()
                   console.log('打开文档成功')
                 },
                 fail: function (res) {    
                    wx.hideLoading();
                    app.alert('文件类型不支持，或文件已损坏');
                    let _that = that;
                    setTimeout(() => {
                        _that.save(filePath);
                    }, 1500);
                 }
               })
            },
            fail: function (res) {
                console.log(res);
                wx.hideLoading()
                app.alert('下载文件失败');
            }
          })
    },
    save(path){
        app.showLoading("正在保存到本地");
        wx.saveFile({
            tempFilePath: path,
            success: function (res) {
                console.log(res);
                wx.hideLoading()
                app.alert('文件已保存到您的手机，请自行查看');
            },
            fail: function (err) {
                console.log(res);
                wx.hideLoading()
                app.alert('保存文件失败');
            }
          });
    },
})